//
//  UIImage+CompressQuality.m
//  BaiDuFace
//
//  Created by 宋朝阳 on 2021/6/4.
//

#import "UIImage+CompressQuality.h"

@implementation UIImage (CompressQuality)

/**
 * 压缩图片使图片文件小于指定大小
 * @param maxLength  压缩最大长度
 */
- (NSData *)compressQualityWithMaxLength:(NSInteger)maxLength {
    NSData *data = UIImageJPEGRepresentation(self, 1);
    for (CGFloat dataCount = 1; dataCount > 0.05; dataCount = dataCount - 0.05) {
        data = UIImageJPEGRepresentation(self, dataCount);
        if (data.length <= maxLength) {
            break;
        }
    }
    
    return data;
}

@end
